import Vue from "vue";
import service from "@service";
import _ from "lodash";
// import staffSelect from "@components/sam/staffSelect/staffSelect";
import { 
    srDictKeyMap,
    PUBLISHING_STATUS,
	PLAN_TYPE,
	ASSIGNMENT_TYPE,
	PLANRUN_TYPE
 } from "@constants";
import { getStaffFormItemRender } from "@/utils/formRender";
import { formItemMap, getTokenInfo, findItem } from "@utils";

export function showTableListSelectHandle2({
    component,
    // isMultiple,
    listName,
    listTipName,
    width,
    height,
    vm,
    keyObj,
    cardNo,
    flag,
    mcard,
    wrkDisciminate,
} = {}) {
    // vm.formConfig[2].disabled = true;
    // vm.formConfig[2].default = cardNo;  
    // eslint-disable-next-line no-async-promise-executor
    return new Promise(async (resolve, reject) => {
        let h = this.$createElement;

        let key = listName + Date.now();

        const confirmClick = async (item,active) => {
            if (item.tradeId){
                let { data }= await service('judExportFlowNo', {
                    data: {
                        flowNo:item.tradeId,
                        wrkDisciminate,
                    },
                    noMessageTip: true,
                });
                if (data.staut=='0'){
                    this.$message.warning(data.respResponse);
                    return
                }
            }
            if(item && String(item.settlecode) === "3") {
                this.$message.warning('该笔通行已由系统后台发起充值返还，无需退费');
                return;
            }
            if (vm && vm[keyObj] && vm[keyObj].length){
                if (vm[keyObj].filter(bill=>{
                    return bill.tradeId === item.tradeId
                }).length){
                    this.$message.warning('不能重复添加');
                    return;
                }
            }else {
                vm[keyObj]=[]
            }
         
            vm[keyObj]=[] //只能展示一条
            vm[keyObj].push(item)
            dialog.close();
            resolve({item,active});
        };

        const cancelClick = () => {
            dialog.close();
            reject();
        };

        let dialog = await this.$store.dispatch("global/showDialog", {
            key: key,
            contentEl: h(component, {
                props: { 
                    singleSelectTableSign: true,
                    cardNoProp:cardNo,
                    flag:flag,
                    mcard:mcard,
                    cardNoDisabled:true
                },
                on: { singleSelected: (v,active) => confirmClick(v,active) },
            }),
            footerEl: (
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" on-click={cancelClick}>
                        取 消
                    </el-button>
                </div>
            ),
            modalProps: {
                width: width || "800px",
                height: height || "400px",
                title: `${listTipName}选择`,
            },
            modalOn: {
                close: () => {
                    dialog.close();
                    reject();
                },
            },
        });
    });
}

export function showTableListSelectHandle({
    component,
    // isMultiple,
    listName,
    listTipName,
    width,
    height,
    vm,
    billQueryProps
} = {}) {
    // eslint-disable-next-line no-async-promise-executor
    return new Promise(async (resolve, reject) => {
        let h = this.$createElement;

        let key = listName + Date.now();

        const confirmClick = (item) => {
            if(item&&String(item.settlecode) === "3") {
                this.$message.warning('该笔通行已由系统后台发起充值返还，无需退费');
                return;
            }
            if (vm&&vm.billTabList&&vm.billTabList.length){
                if (vm.billTabList.filter(bill=>{
                    return bill.tradeId===item.tradeId
                }).length){
                    this.$message.warning('不能重复添加');
                    return;
                }
            }else {
                vm.billTabList=[]
            }

            vm.billTabList.push(item)
            console.log('billTabList===',vm.billTabList);
            dialog.close();
            resolve(item);
        };
        let tabList = [];
        const clickConfirm = () => {
            dialog.close();
            resolve(tabList);
        };

        const manySelected = async (list = [], row) => {
            tabList = list;
        };

        const cancelClick = () => {
            dialog.close();
            reject();
        };

        let dialog = await this.$store.dispatch("global/showDialog", {
            key: key,
            contentEl: h(component, {
                props: { 
                    singleSelectTableSign: true, 
                    ...(billQueryProps||{})
                },
                on: { singleSelected: (v) => confirmClick(v),manySelected: (v,i) => manySelected(v,i), },
            }),
            footerEl: (
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" class='pr-20' on-click={cancelClick}>
                        取 消
                    </el-button>
                    {billQueryProps.tableType=='select'?<el-button size="mini" on-click={clickConfirm}>
                        确 认
                    </el-button>:''}
                </div>
            ),
            modalProps: {
                width: width || "800px",
                height: height || "400px",
                title: `${listTipName}选择`,
            },
            modalOn: {
                close: () => {
                    dialog.close();
                    reject();
                },
            },
        });
    });
}

export function showImportLogHandle({
    component,
    // isMultiple,
    listName,
    listTipName,
    width,
    height,
    vm,
    props
} = {}) {
    return new Promise(async (resolve, reject) => {
        let h = this.$createElement;

        let key = listName + Date.now();

        const cancelClick = () => {
            dialog.close();
            reject();
        };
        let dialog = await this.$store.dispatch("global/showDialog", {
            key: key,
            contentEl: h(component, {
                props: {...(props||{}) },
                on: { },
            }),
            footerEl: (
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" class='pr-20' on-click={cancelClick}>
                        取 消
                    </el-button>
                </div>
            ),
            modalProps: {
                width: width || "800px",
                height: height || "400px",
                title: `${listTipName}`,
            },
            modalOn: {
                close: () => {
                    dialog.close();
                    reject();
                },
            },
        });
    });
}

const FilterTableForSelect = Vue.extend({
    name: "filterTableForSelect",
    props: {
        value: {
            type: [Array]
        },
        keyFlag: { type: [String, Boolean] }, // 列表唯一标识用来判断哪些数据已选择，当showSelected为true时 必填
        showSelected: Boolean,
        maxSelect: {
            type: Number
        },
        isMultiple: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return { selectedData: null, oldFormData: null };
    },
    computed: {
        formConfig() {
            let formConfig = this.$attrs.formConfig;
            if (typeof formConfig === "function") {
                return formConfig(this.$attrs, this);
            }
            return formConfig;
        },
        selectTableData() {
            return [...(this.selectedData||[])];
        },
        columnConfig() {
            let columnConfig = this.$attrs.columnConfig;
            if (typeof columnConfig === "function") {
                columnConfig = columnConfig(this.$attrs, this);
            }
            if (this.showSelected && this.keyFlag) {
                if (columnConfig[0].type === 'select') {
                    columnConfig.splice(0, 1);
                }
                let action = {
                    type: 'render',
                    label: '操作',
                    key: 'action-',
                    render: (h, { data: { row } }) => {
                        let flag = (this.selectTableData || []).some(item => {
                            return item[this.keyFlag] === row[this.keyFlag];
                        })
                        const selectClickHandle = (data, select) => {
                            if (select) {
                                this.selectedData ? this.selectedData.push(data) : (this.selectedData = [data]) ;
                            } else {

                                let index = this.selectTableData.findIndex(item => {
                                    return item[this.keyFlag] === data[this.keyFlag];
                                })
                                this.selectedData.splice(index, 1);
                            }
                            this.emitChange();
                        }
                        return <div>
                            {
                                flag ?
                                    <span class="blue-text-button" on-click={() => selectClickHandle(row, false)}>取消选择</span> :
                                    <span class="blue-text-button" on-click={() => selectClickHandle(row, true)}>选择</span>
                            }
                        </div>
                    }
                }
                if(_.get(columnConfig, `${columnConfig[columnConfig.length-1]}.key`) !== 'action-') {
                    columnConfig.push(action)
                }else {
                    columnConfig[columnConfig.length-1] = action;
                }
            }
            return columnConfig;
        },
        selectTableColumn() {
            let selectTableColumn = this.$attrs.selectTableColumn || [];
            let action = {
                key: 'action-',
                label: '操作',
                type: 'render',
                render: (h, scope) => {
                    return <span on-click={() => {
                        this.selectedData.splice(scope.index, 1);

                    }} class="blue-text-button">删除</span>
                }
            }

            if(_.get(selectTableColumn, `${[selectTableColumn.length-1]}.key`) !== 'action-') {
                selectTableColumn.push(action)
            }else {
                selectTableColumn[selectTableColumn.length-1] = action;
            }
            return selectTableColumn;
        },
        params() {
            let params = this.$attrs.params || {};
            return params;
        },
    },
    watch: {
        value: {
            handler(n) {
                this.selectedData = [...(n||[])]
            },
            immediate: true
        }
    },
    render(h) {
        let { autoLoad, services } = this.$attrs;

        return (
            <el-row>
                <el-col span={this.showSelected ? 14 : 24}>
                    <com-filterTable
                        attrs={{ ...this.$attrs }}
                        class="py-16 px-16 no_card_shadow"
                        table-border={true}
                        showFormFilter={true}
                        showRequestNum={false}
                        filterInline={false}
                        filterCol={this.$attrs.filterCol || 4}
                        services={services}
                        isSingleSelect={!this.isMultiple}
                        autoLoad={autoLoad}
                        params={this.params}
                        filter-form-config={this.formConfig}
                        table-column={this.columnConfig}
                        queryDataHandle={this.queryDataHandle}
                        dataFormatHandle={this.dataFormatHandle}
                        on-selected-change={this.tableSelectionChangeHandle}
                        on-radio-change={this.tableRadioChangeHandle}
                        on-filter-changeOut={this.changeOut}
                    />
                </el-col>
                <el-col span={this.showSelected ? 10 : 0}>
                    <div class="my-8">已选数据</div>
                    <com-table
                        table-column={this.selectTableColumn}
                        pagination={false}
                        auto-load={false}
                        importData={this.selectTableData}
                    />
                </el-col>
            </el-row>
        );
    },
    methods: {
        queryDataHandle(data) {
            let queryDataHandle = this.$attrs.queryDataHandle;

            if (queryDataHandle) {
                data = queryDataHandle(data, this);
            }

            return data;
        },
        dataFormatHandle(data) {
            return data;
        },

        tableSelectionChangeHandle(data) {
            this.selectedData = data;
            this.emitChange();
        },
        tableRadioChangeHandle(data) {
            this.selectedData = data ? [data] : [];
            this.emitChange();
        },
        emitChange() {
            this.$emit("selectChange", this.selectedData);
        },
        changeOut({ key, formData } = {}) {
            this.oldFormData = { ...formData };
        },
    },
});

// 表单弹窗提交
/**
 *
 * @param {Function} footerEl footer生成函数 会传入h等
 * @returns
 */
export const generateFormDialogAsyncHandle = ({
    formName,
    defaultComponentProps = {},
    modalProps = {},
    contentEl,
    footerEl,
}) => {
    return async (vm, { data, componentProps = {}, beforeConfirmHandle } = {}) => {
        let instance = vm;
        let h = instance.$createElement;
        let key = formName + new Date().getTime();
        // eslint-disable-next-line no-async-promise-executor
        return new Promise(async (resolve, reject) => {
            let selected = data;
            var contentInstance = null;

            const confirmClick = async() => {
                // 处理校验
                let result = await contentInstance.$validate();
                // result 需要返回如下格式
                // {
                //  flag: Boolean, // 如果校验成功返回true，将来可以根据该值做一些错误处理
                //  formData: any, // 真正返回的业务数据
                // }
                if (result && result.flag) {
                    resolve(result.formData);
                    dialog.close();
                }
            };

            const cancelClick = () => {
                dialog.close();
                reject();
            };

            let dialog = await instance.$store.dispatch("global/showDialog", {
                key: key,
                contentEl: (
                    contentEl ? (
                        <contentEl
                        on-mounted={(instance) => { contentInstance = instance;}}
                        attrs={{
                            value: data,
                            ...defaultComponentProps,
                            ...componentProps,
                            cancelClick: cancelClick,
                            resolve: resolve
                        }}
                    ></contentEl>

                    ) : (
                        <FilterTableForSelect
                        key={key}
                        attrs={{ value: data, ...defaultComponentProps, ...componentProps }}
                        on-selectChange={(v) => {
                            selected = v;
                        }}
                    />
                    )
                 
                ),
                footerEl:  footerEl ? (
                    footerEl(h, {
                        cancelClick,
                        resolve,
                        reject,
                        getInstance: () => {
                            return contentInstance;
                        }
                    })
                ) : (
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" on-click={cancelClick}>
                            取 消
                        </el-button>
                        <el-button
                            size="mini"
                            type="primary"
                            on-click={confirmClick}
                        >
                            确定
                        </el-button>
                    </div>
                ),
                modalProps: Object.assign(
                    {
                        width: (window.innerWidth||1600)/10*9+'px',
                        // height: (window.innerHeight||900)/4*3+'px',
                        // title: listTipName ? `${listTipName}选择` : '选择',
                    },
                    modalProps
                ),
                modalOn: {
                    close: () => {
                        dialog.close();
                        reject();
                    },
                },
            });
        });
    };
};

export const generateGetListAsyncHandle = ({
    ListName,
    listTipName,
    defaultComponentProps = {},
    height = '400px',
	width = '1000px'
}) => {
    return async (vm, { data, componentProps = {}, beforeConfirmHandle } = {}) => {
        let instance = vm;
        let h = instance.$createElement;
        let key = ListName + new Date().getTime();
        // eslint-disable-next-line no-async-promise-executor
        return new Promise(async (resolve, reject) => {
            let selected = data;

            const confirmClick = () => {
              
                if (!selected || !selected.length) {
                    instance.$message.warning(`请选择${listTipName}！`);
                    return;
                }

                if (defaultComponentProps.message && defaultComponentProps.message(selected)) {
                    let text = defaultComponentProps.message(selected)
                    instance.$message.warning(`${text}`);
                    return
                }

                if (beforeConfirmHandle) {
                    beforeConfirmHandle()
                        .then(() => {
                            dialog.close();
                            resolve(selected);
                        })
                        .catch((e) => {
                            reject();
                        });
                } else {
                    dialog.close();
                    resolve(selected);
                }
            };

            const cancelClick = () => {
                dialog.close();
                // reject();
            };

            let dialog = await instance.$store.dispatch("global/showDialog", {
                key: key,
                contentEl: (
                    <FilterTableForSelect
                        key={key}
                        attrs={{ 
                            value: data, 
                            ...defaultComponentProps, 
                            ...componentProps 
                        }}
                        on-selectChange={(v) => {
                            selected = v;
                        }}
                    />
                ),
                footerEl: (
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" on-click={cancelClick}>
                            取 消
                        </el-button>
                        <el-button
                            size="mini"
                            type="primary"
                            on-click={confirmClick}
                        >
                            确定
                        </el-button>
                    </div>
                ),
                modalProps: {
                    width: (window.innerWidth||1600)/10*9+'px',
                    // height: (window.innerHeight||900)/4*3+'px',
                    title: listTipName ? `${listTipName}选择` : '选择',
                },
                modalOn: {
                    close: () => {
                        dialog.close();
                        reject();
                    },
                },
            });
        });
    };
};

export const getStaffAsync = (staffSelectConfig) => 
    generateGetListAsyncHandle({
        ListName: "staffSelect",
        listTipName: "员工",
        defaultComponentProps: {
            // services:staffSelectConfig.services|| "selectStaffIncludeGroupPagingPost",
            services:staffSelectConfig.services|| "qryStaffInfo",//查询所有人员
            labelWidth: "100px",
            filterCol: 3,
            queryDataHandle(data, vm) {
                data = {
                    ...data,
                }
                return { ...data, provCode: vm.provCode };
            },
            maxHeight:'450px',
            formConfig({ hidenGroup } = {}) {
                let config = [
                    formItemMap.workGrp.apply(window.g_instance, [
                        "工作组",
                        "groupId",
                        {
                            // required: true,
                        },
                    ]),
                    {
                        label: "工号",
                        key: "staffId",
                    },
                    {
                        label: "姓名",
                        key: "staffName",
                    },
                ];
                if (hidenGroup) {
                    config.shift();
                }
                return config;
            },
            columnConfig: [
                {
                    type: _.get(staffSelectConfig, "isMultiple") ? "select" : 'radio',
                    width: "50px",
                    disabled:_.get(staffSelectConfig, "disabled") ? staffSelectConfig.disabled: '',
                    enabled:_.get(staffSelectConfig, "enabled") ? staffSelectConfig.enabled : '',
                },
                {
                    label: "员工姓名",
                    value: "staffName",
                },
                {
                    label: "员工工号",
                    value: "staffId",
                },
                {
                    label: "工作组",
                    value: "groupName",
                    type: 'render',
                    render: (h, { data: { row } }) => {
                        return <div title={row.groupName} class="showMoreRows-2">{row.groupName}</div>
                    }
                },
                {
                    label: "联系电话",
                    value: "mobilePhone",
                },
                {
                    label: "邮箱",
                    value: "emailAddress",
                },
            ],
            selectTableColumn: [
                {
                    label: "员工姓名",
                    value: "staffName",
                },
                {
                    label: "员工工号",
                    value: "staffId",
                },
                {
                    label: "联系电话",
                    value: "mobilePhone",
                },
            ]
        },
    });

export const getSrDynamicElementAsync = generateGetListAsyncHandle({
    ListName: "srDynamicElement",
    listTipName: "动态元素",
    defaultComponentProps: {
        services: "srElementCfgQueryElems",
        queryDataHandle(data, vm) {
            return { ...data, provCode: vm.provCode, tenantId: vm.tenantId };
        },
        formConfig(attrs, vm) {
            let config = [
                {
                    key: "fctNm",
                    label: "受理元素名称",
                },
                {
                    key: "fctNo",
                    label: "受理元素编码",
                },
                {
                    key: "fctTypeCd",
                    label: "受理元素类型",
                    type: "select",
                    options: () => vm.$getSrDict(srDictKeyMap.dynamicEle_type),
                },
                {
                    key: "validFlag",
                    label: "有效标记",
                    type: "select",
                    options: () => vm.$getSrDict(srDictKeyMap.validFlag),
                    default: "1",
                },
            ];
            return config;
        },
        columnConfig: [
            { type: "select", width: 45 },
            { value: "tenantId", label: "租户" },
            { value: "fctNm", label: "受理元素名称" },
            { value: "fctNo", label: "受理元素编码" },
            { value: "fctTypeCdNm", label: "受理元素类型" },
            { value: "validFlagNm", label: "有效标记" },
            { value: "opStaffIdNm", label: "操作员工" },
            { value: "fctSource", label: "要素数据源" },
            { value: "fctLen", label: "要素长度" },
            { value: "hintInfoDesc", label: "提示信息描述" },
            { value: "fctDefaultVal", label: "默认值" },
            { value: "crtTime", label: "创建时间" },
            { value: "modfTime", label: "修改时间" },
        ],
    },
});

// 缺少接口
export const getCustomerAsync = generateGetListAsyncHandle({
    ListName: "customerAsync",
    listTipName: "验证客户",
    defaultComponentProps: {
        services: "useless",
        queryDataHandle(data, vm) {
            return { ...data, provCode: vm.provCode, tenantId: vm.tenantId };
        },
        formConfig(attrs, vm) {
            let formData = _.get(vm, "oldFormData") || { searchType: "1" };
            let configMap = {
                cardNm: {
                    key: "cardNm",
                    label: "卡号",
                },
                idType: {
                    key: "idType",
                    label: "证件类型",
                    type: "select",
                    options: [
                        { value: "1", label: "身份证" },
                        { value: "2", label: "军官证" },
                    ],
                },
                idNm: {
                    key: "idNm",
                    label: "证件号码",
                },
                customerName: {
                    key: "customerName",
                    label: "客户名称",
                },
                customerNumber: {
                    key: "customerNumber",
                    label: "客户号",
                },
                vehiclePlate: {
                    key: "vehiclePlate",
                    label: "车牌号",
                },
                vehicleColor: {
                    key: "vehicleColor",
                    label: "车牌颜色",
                },
                vehicleNm: {
                    key: "vehicleNm",
                    label: "车辆识别代码",
                },
            };
            let config = [
                {
                    key: "searchType",
                    label: "查询类型",
                    type: "select",
                    changeToEmit: true,
                    required: true,
                    default: "1",
                    options: [
                        { value: "1", label: "卡号" },
                        { value: "2", label: "客户名称" },
                        { value: "3", label: "客户号" },
                        { value: "4", label: "车牌号码" },
                    ],
                },
                //     options: () => vm.$getSrDict(srDictKeyMap.validFlag),
            ];
            if (formData.searchType === "1") {
                config.push(
                    ...[configMap.cardNm, configMap.idType, configMap.idNm]
                );
            } else if (formData.searchType === "2") {
                config.push(
                    ...[
                        configMap.customerName,
                        configMap.idType,
                        configMap.idNm,
                    ]
                );
            } else if (formData.searchType === "3") {
                config.push(...[configMap.customerNumber]);
            } else if (formData.searchType === "4") {
                config.push(
                    ...[
                        configMap.vehiclePlate,
                        configMap.vehicleColor,
                        configMap.vehicleNm,
                    ]
                );
            }
            return config;
        },
        columnConfig: [
            { type: "select", width: 45 },
            { value: "key1", label: "姓名" },
            { value: "key2", label: "卡号" },
            { value: "key3", label: "手机号" },
        ],
    },
});

export const getAgentAsync = generateGetListAsyncHandle({
    ListName: "agentSelect",
    listTipName: "坐席",
    defaultComponentProps: {
        // dataType:'params',
        services: "queryAgentWithoutShift",
        // services: "queryStaffId",
        queryDataHandle(data, vm) {
            return { ...data};
        },
        formConfig: [
            {
                key: 'staffId',
                label: '员工id'
            }

        ],
        columnConfig: [
            {
                type: "select",
                width: "50px",
            },
            {
                label: "坐席编号",
                value: "staffId",
            },
            {
                label: "坐席名称",
                value: "staffName",
            },
        ],
    },
});


export const getSendMessage = generateGetListAsyncHandle({
    ListName: "sendMessage",
    listTipName: "短信",
    defaultComponentProps: {
        // dataType:'params',
        // services: "queryAgentWithoutShift",
        services: "getSmsAudit",
        labelWidth: "auto",
        queryDataHandle(data, vm) {
            //查询前处理请求入参
            console.log(data,"3333333333");
            data.sbmtStaffId=data.sbmtStaffId?.staffId
            return { ...data};
        },
        formConfig(vm) {
            let config = [
                {
                    key: "wrkfmId",
                    label: "工单编号",
                },
                {
                    key: "recverNum",
                    label: "联系号码",
                },
                {
                    // key: "sbmtTimeStart",
                    label: "发送时间",
                    type: "datetimerange",
                    keyRange: ["sbmtTimeStart", "sbmtTimeEnd"],
                    col:2,
                    // type: "datetime",
                    // props: {
                    //     "value-format": "yyyy-MM-dd HH:mm:ss",
                    // },
                },
                {
                    key: "sdFlag",
                    label: "发送状态",
                    type: "select",
                    // options: () => vm.$getSrDict(srDictKeyMap.CONTACT_TYPE),
                    options: [
                        { key: "1", label: "已发送" },
                        { key: "2", label: "未发送" },
                        { key: "4", label: "发送失败" },
                    ],
                },
                {
                    key: "contactType",
                    label: "短信类型",
                    type: "select",
                    // options: () => vm.$getSrDict(srDictKeyMap.CONTACT_TYPE),
                    options: [
                        { key: "1", label: "短信下发" },
                        { key: "2", label: "人工外呼" },
                        { key: "3", label: "智能外呼" },
                    ],
                },
                {
                    label: "提交人",
                    key: "sbmtStaffId",
                    type: "render",
                    render: getStaffFormItemRender({
                        staffSelectConfig: {
                            hidenGroup: true,
                            autoLoad: true,
                            params: {},
                            isMultiple: false,
                        },
                    }),
                },

                // formItemMap.staff.apply(this, ['员工'])
            ];
            return config;
        },
        columnConfig: [
            {
                type: "select",
                width: "50px",
            },
            {
                label: "工单编号",
                value: "wrkfmId",
            },
            {
                label: "联系号码",
                value: "recverNum",
            },
            {
                label: "发送时间",
                value: "sbmtTime",
            },
            {
                label: "短信类型",
                value: "smsTypeCd",
                type: 'render',
                render: (h, { data: { row } }) => {
                  let options=[
                        { key: "1", label: "短信下发" },
                        { key: "2", label: "人工外呼" },
                        { key: "3", label: "智能外呼" },
                    ]

                   let smsTypeCd=options.filter(item=>{
                        return item.key==row.smsTypeCd
                    })
                    return (<div>{smsTypeCd[0]?.label}</div>)
                }
            },
            {
                label: "提交人",
                value: "sbmtStaffId",
            },
            {
                label: "短信内容",
                value: "smsCntt",
            },
        ],
    },
});
export const getIVRAsync = (selectConfig) => generateGetListAsyncHandle({
	ListName: "IVRSelect",
	listTipName: "IVR",
	height: 'auto',
	defaultComponentProps: {
			// services:staffSelectConfig.services|| "selectStaffIncludeGroupPagingPost",
			services:selectConfig.services|| "cmg_queryIVR",//查询所有人员  cmg_queryIVR
			queryDataHandle(data, vm) {
				const params = {
					start: -1,
					pageNum: -1,
                    state: "生效"
				}
					return { ...data, ...params};
			},
			pagination: false,
			maxHeight:'440px',
			formConfig({ hidenGroup } = {}) {
					let config = [
							{
									label: "IVR号",
									key: "id",
							},
							{
									label: "IVR名称",
									key: "name",
							},
					];
					if (hidenGroup) {
							config.shift();
					}
					return config;
			},
			columnConfig: [
					{
							type: _.get(selectConfig, "isMultiple") ? "select" : 'radio',
							width: "50px",
							disabled:_.get(selectConfig, "disabled") ? selectConfig.disabled: '',
							enabled:_.get(selectConfig, "enabled") ? selectConfig.enabled : '',
					},
					{
							label: "IVR号",
							value: "id",
					},
					{
							label: "IVR名称",
							value: "name",
					},
					{
							label: "IVR描述",
							value: "content",
					},
					{
							label: "创建人",
							value: "creater",
					},
					{
							label: "创建时间",
							value: "time",
					},
					{
							label: "状态",
							value: "state",
					},
			],
			selectTableColumn: [
					{
							label: "IVR号",
							value: "id",
					},
					{
							label: "IVR名称",
							value: "name",
					},
					{
							label: "状态",
							value: "state",
					},
			]
	},
});
export const checkStaffAsync = (selectConfig) => generateGetListAsyncHandle({
	ListName: "checkStaffSelect",
	listTipName: "员工",
	height: 'auto',
	defaultComponentProps: {
			services:selectConfig.services|| "aiqm_getQmPeople",//查询所有人员
			queryDataHandle(data, vm) {
				console.log("🚀 ~ file: components.js ~ line 1076 ~ queryDataHandle ~ data", data,selectConfig)
				const params = {
					...data,
					groupId: data.groupId ? data.groupId[0] : ''
				}
					return { params};
			},
			pagination: true,
			dataType: 'params',
			maxHeight:'300px',
			formConfig({ hidenGroup } = {}) {
					let config = [
						formItemMap.workGrp.apply(window.g_instance, [
								"工作组",
								"groupId",
						]),
						{
								label: "工号",
								key: "staffId",
						},
						{
								label: "姓名",
								key: "staffName",
						},
					];
                    if(selectConfig.services==='qmPlanGetQmPeopleByOrgIds'){
                        config = [
                            formItemMap.acptStaffIdDepart.apply(window.g_instance, [
                                "组织机构",
                                "orgIds",
                                {
                                    props: {
                                        props: {
                                            // multiple: true,
                                            checkStrictly: true,
                                        },
                                    },
                                },
                            ]),
                            {
                                label: "员工姓名",
                                key: "staffName",
                                type: "input"
                            },
                            {
                                label: "员工工号",
                                key: "staffId",
                                type: "input"
                            }
                        ]
                    }
					if (hidenGroup) {
							config.shift();
					}
					return config;
			},
			columnConfig: [
					{
							type: _.get(selectConfig, "isMultiple") ? "select" : 'radio',
							width: "50px",
							disabled:_.get(selectConfig, "disabled") ? selectConfig.disabled: '',
							enabled:_.get(selectConfig, "enabled") ? selectConfig.enabled : '',
					},
					{
							label: "员工工号",
							value: "staffId",
					},
					{
							label: "员工名称",
							value: "staffName",
					},
					{
							label: "邮箱",
							value: "emailAddress",
					},
					{
							label: "电话",
							value: "mobilePhone",
					},
			],

	},
});


export const examinationPlanAsync = (selectConfig) => generateGetListAsyncHandle({
	ListName: "examinationPlanSelect",
	listTipName: "考评计划",
	height: 'auto',
	defaultComponentProps: {
			services:selectConfig.services|| "aiqm_qmPlan_selectByParams",
			queryDataHandle(data, vm) {
				const params = {
					...data,
					tenantId: window.g_instance.tenantKey
				}
					return { params};
			},
			pagination: true,
			// dataType: 'params',
			maxHeight:'300px',
			formConfig({ hidenGroup } = {}) {
					let config = [
						{
								label: "计划名称",
								key: "planName",
						},
						{
								label: "发布状态",
								key: "haltFlag",
								type: 'select',
								options: PUBLISHING_STATUS
						},
						{
								key: "datetimerange",
								label: '创建时间',
								col: 2,
								type: "datetimerange",
								keyRange: ["createTimeStart", "createTimeEnd"],
								// props: {
								// 		"value-format": "yyyy-MM-dd HH:mm:ss",
								// },
						},
						{
								label: "计划类型",
								key: "planType",
								type: 'select',
								options: PLAN_TYPE
						},
					];
					return config;
			},
			columnConfig: [
					{
							type: _.get(selectConfig, "isMultiple") ? "select" : 'radio',
							width: "50px",
							fixed: "left",
							disabled:_.get(selectConfig, "disabled") ? selectConfig.disabled: '',
							enabled:_.get(selectConfig, "enabled") ? selectConfig.enabled : '',
					},
					{
							label: "计划名称",
							width: '150px',
							value: "planName",
					},
					{
							label: "计划类型",
							value: "planType",
							type: 'render',
							render: (h, { data: { row }}) => {
								return (<span>{findItem(PLAN_TYPE, row?.planType)}</span>)
							}
					},
					{
							label: "考评模板",
							value: "templateName",
					},
					{
							label: "抽取策略",
							value: "pName",
					},
					{
							label: "任务分派方式",
							value: "manOrAuto",
							width: '120px',
							type: 'render',
							render: (h, { data: { row }}) => {
								return (<span>{findItem(ASSIGNMENT_TYPE, row?.manOrAuto)}</span>)
							}
					},
					{
							label: "执行方式",
							value: "planRuntype",
							type: 'render',
							render: (h, { data: { row }}) => {
								return (<span>{findItem(PLANRUN_TYPE, row?.planRuntype)}</span>)
							}
					},
					{
							label: "执行时间",
							value: "planRuntime",
					},
					{
							label: "发布状态",
							value: "haltFlag",
							type: 'render',
							render: (h, { data: { row }}) => {
								return (<span>{findItem(PUBLISHING_STATUS, row?.haltFlag)}</span>)
							}
					},
					{
							label: "计划开始时间",
							value: "planStarttime",
							width: '155px',
					},
					{
							label: "计划结束时间",
							value: "planEndtime",
							width: '155px',
					},
					{
							label: "描述",
							value: "remark",
					},
			],

	},
});

export const examinationTemplateAsync = (selectConfig) => generateGetListAsyncHandle({
	ListName: "examinationTemplateSelect",
	listTipName: "考评模板",
	height: 'auto',
	defaultComponentProps: {
			services:selectConfig.services|| "aiqm_checkTemplate_selectByParams",
			queryDataHandle(data, vm) {
				const params = {
					...selectConfig.params,
					...data,
					tenantId: g_instance.tenantKey
				}
					return {params};
			},
			pagination: true,
			// dataType: 'params',
			maxHeight:'300px',
			formConfig({ hidenGroup } = {}) {
					let config = [
						{
								label: "模板名称",
								key: "templateName",
						},
					];
					return config;
			},
			columnConfig: [
					{
							type: _.get(selectConfig, "isMultiple") ? "select" : 'radio',
							width: "50px",
							fixed: "left",
							disabled:_.get(selectConfig, "disabled") ? selectConfig.disabled: '',
							enabled:_.get(selectConfig, "enabled") ? selectConfig.enabled : '',
					},
					{
							label: "模板编码",
							value: "templateId",
					},
					{
							label: "模板名称",
							value: "templateName",
					},
					{
							label: "备注",
							value: "remark",
					},
					{
							label: "分值类型",
							value: "scoreType",
					},
					{
							label: "创建时间",
							value: "createTime",
					},
			],

	},
});

